<?php
/*
*All rights reserved: Json.
*Links:http://www.liyaoquan.cn.
*Links:http://imarkchina.cn.
*Links:http://www.imarkchina.cn.
*/
Class PinglunLeve{

	/**
	 * 评论无限级分类
	 * @param  [type]  $data  [接收数组]
	 * @param  integer $pid   [需要查的id号]
	 * @param  integer $check [###]
	 * @return [type]         [description]
	 */
	Static Public function getPL($data, $html = 10, $pid = 0, $check = 0){
		$arr = array();
		foreach ($data as $v) {
			if ($v['pid'] == $pid) {
				$v['check'] = $check;
				$v['html'] = ($html == 110) ? 10 : $html;
				$arr[] = $v;
				$arr = array_merge((array)$arr, (array)self::getPL($data, ($html + 10), $v['rid'], ($check + 1)));
			}
		}
		return $arr;
	}

	/**
	 * 检查需要替换用户名
	 * @param  [type]  $data [接收数组]
	 * @param  integer $pid  [需要检查id]
	 * @return [type]        [description]
	 */
	Static Public function getUsername($data, $pid = 1){
		$arr = array();
		foreach ($data as $v) {
			if ($v['rid'] == $pid) {
				$arr = $v;
			}
		}
		$userid = (isset($arr['user_id'])) ? $arr['user_id'] : '';
		$uid = loadfile(C('user').$userid.'.php');
		if ($uid) {
			return $uid['username'];
		} else {
			$rename = (isset($arr['username'])) ? $arr['username'] : '';
			return $rename;
		}
	}

	/**
	 * 根据PID取出评论回复用户名，邮箱
	 * @param  [type]  $data [description]
	 * @param  integer $pid  [description]
	 * @return [type]        [description]
	 */
	Static Public function pinglunreemail($data, $pid = 0){
		$arr = array();
		foreach ($data as $v) {
			if ($v['rid'] == $pid) {
				$arr['rename'] = $v['username'];
				$arr['reemail'] = $v['useremail'];
			}
		}
		return $arr;
	}
}